package com.lxm.controller;


import com.lxm.dto.*;
import com.lxm.service.LoginService;
import com.lxm.service.UserInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户信息表 前端控制器
 * </p>
 *
 * @author ${author}
 * @since 2024-10-02
 */
@RestController
@RequestMapping("/user/user_info")
@Tag(name = "用户信息管理")
public class UserInfoController {
    @Resource
    private UserInfoService userInfoService;
    @Resource
    private LoginService loginService;

    @Operation(summary = "用户注册")
    @PostMapping
    public Result register(@RequestBody UserInfoDTO userInfo) {
        return userInfoService.register(userInfo);
    }


    @Operation(summary = "获取用户信息")
    @GetMapping("/getDetails")
    public Result getDetails() {
        return userInfoService.getDetails();
    }

    @Operation(summary = "修改用户基础信息", description = "修改昵称和头像放在另一个接口中了")
    @PutMapping("/update")
    public Result modifyUserInfo(@RequestBody UserInfoModifyDTO userInfo) {
        return userInfoService.modifyUserInfo(userInfo);
    }

    @Operation(summary = "用户修改昵称和头像")
    @PutMapping("/update/icon")
    //前端控制修改什么，可以双修改，前端传什么就修改什么
    public Result updateNickNameAndIcon(@RequestBody UserNickNameAndIconModifyDTO
                                                userNickNameAndIcon) {
        return loginService.updateNickNameAndIcon(userNickNameAndIcon);
    }

    @Operation(summary = "用户注销")
    @DeleteMapping("/delete")
    public Result deleteUser(HttpServletRequest request) {
        return userInfoService.deleteUser(request);
    }

    @Operation(summary = "用户修改密码")
    @PutMapping("/update/password")
    public Result updatePassword(@RequestBody PasswordEditDTO userPassword) {
        return userInfoService.updatePassword(userPassword);
    }

    @Operation(summary = "用户忘记密码")
    @PutMapping("/forget/password")
    public Result forgetPassword(@RequestBody PasswordEditDTO userPassword) {
        return userInfoService.forgetPassword(userPassword);
    }

}

